/**
 * Project Name:fastPlat
 * File Name:MemberVisitRecordsController.java
 * Package Name:com.fast.user.web.controller.member
 * Date:2017年05月27日 18时06分04秒
 * Copyright (c) 2017, lsflu@126.com All Rights Reserved.
 *
*/

package com.fast.user.web.controller.member;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.fast.base.db.page.PageView;
import com.fast.base.db.sql.AbstractSqlGenerator;
import com.fast.base.model.AnoSysLog;
import com.fast.base.util.LogUtils;
import com.fast.base.util.StringUtils;
import com.fast.base.util.web.ResponseData;
import com.fast.base.util.web.ResponseEnum;
import com.fast.base.web.BaseController;
import com.fast.common.userCache.UserRequestUtils;
import com.fast.user.model.member.MemberVisitRecords;
import com.fast.user.service.member.MemberVisitRecordsService;
import com.fast.user.web.form.web.MemberVisitRecordsForm;

/**
 * ClassName:MemberVisitRecordsController <br/>
 * 用途: 用户浏览记录 web控制类 <br/>
 * 开发人员：lushuifa  http://lushuifa.iteye.com/
 * 邮箱:lsflu@126.com
 * @version  1.0
 * @since    JDK 1.6
 * @see
 * Date:     2017年05月27日 18时06分04秒 <br/> 	 
 */
@Controller
@RequestMapping("/memberVisitRecords")
public class MemberVisitRecordsController extends BaseController{
	
	@Resource(name="memberVisitRecordsService")
	private MemberVisitRecordsService memberVisitRecordsService;

	/**
	 * 编辑用户浏览记录信息
	 * @param imageUrl
	 * @return
	 */
	@RequestMapping("/editMemberVisitRecords.do")
	@ResponseBody
	@AnoSysLog(actionName="编辑用户浏览记录信息")
	public ResponseData editMemberVisitRecords(){
		ResponseData responseData = new ResponseData();
		MemberVisitRecords memberVisitRecords = null;
		try {
			int id = webUtil.getInt("id");
			if(id>0){
				memberVisitRecords = this.memberVisitRecordsService.getById(MemberVisitRecords.class,id);
				memberVisitRecords = (MemberVisitRecords) webUtil.bindDataToBean(memberVisitRecords);
			}else{
				memberVisitRecords = new MemberVisitRecords();
				memberVisitRecords = (MemberVisitRecords) webUtil.bindDataToBean(memberVisitRecords);
				UserRequestUtils.bindCreaterInfo(memberVisitRecords);
			}
			UserRequestUtils.bindEditorInfo(memberVisitRecords);
			if(this.memberVisitRecordsService.merge(memberVisitRecordsService)!=null){
				responseData.buildResult(ResponseEnum.EDIT_SUCCESS);
			}else{
				responseData.buildResult(ResponseEnum.EDIT_FAILUE);
			}
		} catch (Exception e) {
			e.printStackTrace();
			responseData.failue();
		}
		return responseData;
	}
	
	/**
	 * 删除用户浏览记录信息到回收站
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/delMemberVisitRecordsByIdForHS.do")
	@AnoSysLog(actionName="删除用户浏览记录到回收站")
	public ResponseData delMemberVisitRecordsByIdForHS(int id) {
		LogUtils.info("delMemberVisitRecordsByIdForHS id=:"+id);
		ResponseData responseData = new ResponseData();
		try {
			String sql = "update "+AbstractSqlGenerator.getTableName(MemberVisitRecords.class)+" set delete_Flag=1 where id="+id;
			boolean actionFlag = memberVisitRecordsService.modifyRow(sql)>0;
			responseData.setCode(actionFlag?"00":"01");
			if(actionFlag){
				responseData.buildResult(ResponseEnum.DELETE_SUCCESS);
			}else{
				responseData.buildResult(ResponseEnum.DELETE_FAILUE);
			}
		} catch (Exception e) {
			e.printStackTrace();
			responseData.failue();
		}
		LogUtils.info("delMemberVisitRecordsByIdForHS responseData=:"+responseData.toString());
		return responseData;
	}

	/**
	 * 删除用户浏览记录信息
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/delMemberVisitRecordsById.do")
	@AnoSysLog(actionName="彻底删除用户浏览记录")
	public ResponseData delMemberVisitRecordsById(int id) {
		LogUtils.info("delMemberVisitRecordsById id=:"+id);
		ResponseData responseData = new ResponseData();
		try {
			boolean actionFlag = memberVisitRecordsService.deleteById(MemberVisitRecords.class, id);
			responseData.setCode(actionFlag?"00":"01");
			if(actionFlag){
				responseData.buildResult(ResponseEnum.DELETE_SUCCESS);
			}else{
				responseData.buildResult(ResponseEnum.DELETE_FAILUE);
			}
		} catch (Exception e) {
			e.printStackTrace();
			responseData.failue();
		}
		LogUtils.info("delMemberVisitRecordsById responseData=:"+responseData.toString());
		return responseData;
	}
	
	/**
	 * 删除多个用户浏览记录信息
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/batchDelMemberVisitRecords.do")
	@AnoSysLog(actionName="批量删除用户浏览记录评论")
	public ResponseData batchDelMemberVisitRecords(String ids){
		ResponseData responseData = new ResponseData();
		try {
			int actionCount = memberVisitRecordsService.deleteByIds(MemberVisitRecords.class, ids);
			if(actionCount>0){
				responseData.buildResult(ResponseEnum.DELETE_SUCCESS);
			}else{
				responseData.buildResult(ResponseEnum.DELETE_FAILUE);
			}
		} catch (Exception e) {
			e.printStackTrace();
			responseData.failue();
		}
		return responseData;
	}
	
	/**
	 * 分页得到用户浏览记录列表
	 * @return PageView<MemberVisitRecords>
	 * @throws IOException 
	 */
	@ResponseBody
	@RequestMapping("/getMemberVisitRecordsList.do")
	public Object getMemberVisitRecordsList(MemberVisitRecordsForm memberVisitRecordsForm){
		LogUtils.info("getMemberVisitRecordsList param:"+memberVisitRecordsForm.toString());
		Map<String,Object> gridMap = new HashMap<String,Object>();
		PageView<MemberVisitRecords> pageView = null;
		try {
			pageView = this.memberVisitRecordsService.getMemberVisitRecordsList(memberVisitRecordsForm);
			gridMap.put("total", pageView.getTotalRecord());
			gridMap.put("rows", pageView.getRecords());
		} catch (Exception e) {
			LogUtils.error("getMemberVisitRecordsList err:",e);
		}
		LogUtils.info("getMemberVisitRecordsList result:"+pageView.toString());
 		return gridMap;
	}
	
	/**
	 * 查询用户浏览记录详情
	 * @param id
	 * @return
	 */
	@RequestMapping("/getMemberVisitRecordsDetail.do")
	public ModelAndView getMemberVisitRecordsDetail(int id,String actionType) {
		ModelAndView mv = new ModelAndView();
		MemberVisitRecords bean = memberVisitRecordsService.queryForBeanById(MemberVisitRecords.class, id);
		try {
			mv.addObject("memberVisitRecords",bean);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(StringUtils.equals(actionType,"update")){
			mv.setViewName("/adminMain/memberVisitRecords/memberVisitRecords-add.jsp");
		}else{
			mv.setViewName("/adminMain/memberVisitRecords/memberVisitRecords-detail.jsp");
		}
		return mv;
	}
}

